﻿using System;
using System.Linq;
using System.Text;

namespace Vkontakte.Api.Operations
{
	[ApiMethod("places.getCities")]
	public sealed class PlacesGetCities
		:Base30ApiOperation
	{
		private City[] _result;

		protected override void Compile()
		{
			AddParameter( "method", "places.getCities" );
			AddParameter( "country", CountryID.Value.ToString() );
			if (!string.IsNullOrEmpty( SearchQuerry ))
			{
				AddParameter( "q", SearchQuerry );
			}
			base.Compile();
		}

		protected override void ParseData(string data)
		{
			ListingResponce r = Serializer.LoadObjectXmlString<ListingResponce>( data );
			_result = r.Cities;
			base.ParseData(data);
		}

		protected internal override bool CheckParams()
		{
			return CountryID != null;
		}

		public int? CountryID
		{
			get; set;
		}

		public string SearchQuerry { get; set; }

		public City[] GetResult()
		{
			return _result;
		}
	}
}
